package com.xkdx.guangguang.fragment.myinfomation;

import java.util.HashMap;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.xkdx.caipiao.R;
import com.xkdx.guangguang.fragment.BaseFragment;
import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.InfoManager;

public class InfoDetailFragment extends BaseFragment {

	private View view_info_detail;
	private Button infodetail_back;
	private TextView tv_infodetail_summary, tv_infodetail_time,	tv_infodetail_detail;
	private InfoManager infoManager;
	private InfoNotificationFragment infoNotificationFragment;
	private FragmentTransaction transaction;
	/**
	 * 用于对Fragment进行管理
	 */
	private FragmentManager fragmentManager;

	//

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		infoManager = (InfoManager) getArguments().get("info");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		fragmentManager = getFragmentManager();
		transaction = fragmentManager.beginTransaction();
		view_info_detail = inflater.inflate(R.layout.info_detail, container,
				false);
		findView();
		setOnClick();
		setValues();
		return view_info_detail;
	}

	private void setValues() {
		String title = infoManager != null
				&& !("".equals(infoManager.getTitle())) ? infoManager
				.getTitle() : "暂无";
		String time = infoManager != null
				&& !("".equals(infoManager.getSendTime())) ? infoManager
				.getSendTime() : "";
		String detail = infoManager != null
				&& !("".equals(infoManager.getMessage())) ? infoManager
				.getMessage() : "暂无";
		tv_infodetail_summary.setText(title);
		tv_infodetail_time.setText(time);
		tv_infodetail_detail.setText(detail);
	}

	@Override
	public void findView() {
		infodetail_back = (Button) view_info_detail
				.findViewById(R.id.infodetail_back);
		tv_infodetail_summary = (TextView) view_info_detail
				.findViewById(R.id.tv_infodetail_summary);
		tv_infodetail_time = (TextView) view_info_detail
				.findViewById(R.id.tv_infodetail_time);
		tv_infodetail_detail = (TextView) view_info_detail
				.findViewById(R.id.tv_infodetail_detail);

	}

	@Override
	public void setOnClick() {
		infodetail_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				infoNotificationFragment = (InfoNotificationFragment) fragmentManager
						.findFragmentByTag("infoNotificationFragment");
				if (infoNotificationFragment == null) {
					// 如果NewsFragment为空，则创建一个并添加到界面上
					infoNotificationFragment = new InfoNotificationFragment();
					transaction.add(R.id.fragment, infoNotificationFragment);
				} else {
					// 如果NewsFragment不为空，则直接将它显示出来
					transaction.show(infoNotificationFragment);
				}
				transaction.commit();
				getFragmentManager().popBackStack();
			}
		});
	}

	@Override
	public void showLoading() {

	}

	@Override
	public void showLoaded(HashMap<String, AbsModule> map) {

	}

	@Override
	public void showClick(HashMap<String, AbsModule> map) {

	}

	@Override
	public void showLoadMore(HashMap<String, AbsModule> map) {

	}

}
